import { _decorator, Component, instantiate, Node, Prefab, Vec3 } from 'cc';
import { heiziManager } from './heiziManager';
import { Ikun } from './IkunControl';
const { ccclass, property } = _decorator;

@ccclass('gameControl')
export class gameControl extends Component {
  @property(Prefab)
  ikunPre: Prefab = null
  ikun: Node = null
  canvasNode: Node = null
  gameOverUI: Node = null
  _heiziManager: heiziManager = null

  onLoad() {
    this.canvasNode = this.node.getParent()
    this.ikun = this.canvasNode.getChildByName('ikun')
    this.gameOverUI = this.canvasNode.getChildByName('GameOver')
    this._heiziManager = this.canvasNode.getChildByName('heiziManage').getComponent(heiziManager)

  }
  start() {

  }

  update(deltaTime: number) {

  }
  resetGame() {
    const ikun = instantiate(this.ikunPre)
    ikun.getComponent(Ikun).isDead = false
    ikun.setPosition(new Vec3(-323, -188, 0))
    this.canvasNode.addChild(ikun)
    //清除所有小黑子
    this.canvasNode.children.filter((item: Node) => item.name === 'heizi').forEach((item: Node) => this.schedule(() => {
      item.destroy()
    }))
    this.gameOverUI.active = false
    this._heiziManager.isCreateHeizi = true
  }
  stopGame() {
    this.ikun.destroy()
  }
}


